var currentPage;
var iconPath = "icons/";
var USELOG = false;

var counter = 1;
var g_showLabels = true;

////////////////////////////////////////////////////////////////////////////////////
function init(hasIFrame) {
	
	var args = getArgs();
	if (args.category) {
		g_category = args.category;
	}
	
	g_showLabels = document.getElementById('chk_show_labels').checked
	//alert(g_showLabels);
	initMap();
	
	/*
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		
		map.addControl(new GSmallMapControl());
		
		// sets global vars - watch for side effects
		getExtents();
		map.enableDoubleClickZoom();
		map.setCenter(new GLatLng(g_centerLatitude, g_centerLongitude), g_startZoom);
		map.setMapType(G_HYBRID_MAP);
		
	}
	*/
	
	var dataArrayLen = markers.length;

	
	writeLog(dataArrayLen);
	for(i=0; i<dataArrayLen; i++) {	
		addMarker(markers[i].latitude, markers[i].longitude, markers[i].name, markers[i].url, markers[i].userid, markers[i].add_date, markers[i].category);
		writeLog(markers[i].latitude);
	}

	handleResize();
	
	if (dataArrayLen == 0 ) {
		alert("No locations have been added to this MapBlog. You can add a location by clicking the --Add New Locations-- link (top right)");	
	}
	//alert(counter);
}

/////////////////////////////////////////////////////////////////////////////////////
// This should be removed from production code ... but it is very useful
/////////////////////////////////////////////////////////////////////////////////////
function writeLog(message) {
	if (USELOG) {
		GLog.write(message);	
	};
}

//////////////////////////////////////////////////////////////////////////////////
function isdefined( variable) {
    return (typeof(window[variable]) == "undefined")?  false: true;
}

/////////////////////////////////////////////////////////////////////////////////
function openPage() {
	w = window.open(currentPage,"","width=800,height=350,status=yes,resizable=yes, scrollbars=yes");
}



//////////////////////////////////////////////////////////////////////////////////////
function addMarker(latitude, longitude, description, url, userid, add_date, category) {
	counter++;

	//var standard_icon = new GIcon();
	//standard_icon.image = "mapblog_point.png";
	//GLog.write(standard_icon.image);
	//standard_icon.size = new GSize(24, 32);
	//GLog.write(userid);
	thePos = add_date.indexOf("00:");
	newDate = add_date.substr(0, thePos-1);
	
	var theDesc = "Added by: " + userid + " - on: " + newDate;

	//var theDesc = "Added by: " + userid + " - on: " + add_date;
	var thePoint = new GLatLng(latitude, longitude);
	var iconPath = "../shared_sp08/icons/";

	
	if (category == "module1") {
		icon_name = "icong_1.png";	
	} else if (category == "module2") {
		icon_name = "iconp_2.png";
	} else if (category == "module3") {
		icon_name = "iconr_3.png";
	} else if (category == "module4") {
		icon_name = "icong_4.png";
	} else if (category == "module5") {
		icon_name = "icong_5.png";
	} else if (category == "module6") {
		icon_name = "icong_6.png";
	} else if (category == "module7") {
		icon_name = "icong_7.png";
	} else if (category == "module8") {
		icon_name = "icong_8.png";
	} else if (category == "module9") {
		icon_name = "icong_9.png";
		
	} else {
		icon_name = "location.png";
	}
	
	var fullIconPath = iconPath + icon_name;
	var theIcon = new GIcon(G_DEFAULT_ICON, fullIconPath);	
	theIcon.iconSize = new GSize(20, 34);
	theIcon.shadowSize = new GSize(20, 34);
	var marker = new GMarker(thePoint, {icon: theIcon});
	
	//var marker = new GMarker(thePoint);
	
  	GEvent.addListener(marker, 'click', function() { getPageByClick2(url);} );
  
	GEvent.addListener(marker,'mouseover',function() {
		marker.openToolTip(theDesc);
	});

	GEvent.addListener(marker,'mouseout',function() {
		marker.closeToolTip();
	});


	if (g_showLabels == true) {		
		makebox(thePoint, description);
	}
  
	map.addOverlay(marker);
}

//////////////////////////////////////////////////////////////////////////


window.onresize = handleResize;
//window.onload = init;
